package com.wx.uid.controller;

import com.wx.uid.UidGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class UidGeneratorController implements InitializingBean {

    @Autowired
    private UidGenerator uidGenerator;

    @GetMapping("/get")
    public String getUid() {
        long uid = 0;
        try {
            uid = uidGenerator.getUID();
        } catch (Exception e) {
            log.error("获取uid");
        }
        log.info("uid:{}", uid);
        return String.valueOf(uid);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        long uid = uidGenerator.getUID();
        log.info("UID: {}", uid);
        log.info("UID: {}", uidGenerator.parseUID(uid));
    }
}

